﻿using System;
using System.Collections.Generic;
using System.Linq;
using Helpers;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.Conversation;
using TaleWorlds.CampaignSystem.Extensions;
using TaleWorlds.CampaignSystem.MapEvents;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Roster;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;

namespace TaleWorlds.CampaignSystem.Issues
{
	// Token: 0x02000313 RID: 787
	public class LordNeedsHorsesIssueBehavior : CampaignBehaviorBase
	{
		// Token: 0x06002D72 RID: 11634 RVA: 0x000BE3C8 File Offset: 0x000BC5C8
		private void OnCheckForIssue(Hero hero)
		{
			if (this.ConditionsHold(hero))
			{
				Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(new PotentialIssueData.StartIssueDelegate(this.OnIssueSelected), typeof(LordNeedsHorsesIssueBehavior.LordNeedsHorsesIssue), IssueBase.IssueFrequency.VeryCommon, null));
				return;
			}
			Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(typeof(LordNeedsHorsesIssueBehavior.LordNeedsHorsesIssue), IssueBase.IssueFrequency.VeryCommon));
		}

		// Token: 0x06002D73 RID: 11635 RVA: 0x000BE42C File Offset: 0x000BC62C
		private IssueBase OnIssueSelected(in PotentialIssueData pid, Hero issueOwner)
		{
			return new LordNeedsHorsesIssueBehavior.LordNeedsHorsesIssue(issueOwner);
		}

		// Token: 0x06002D74 RID: 11636 RVA: 0x000BE434 File Offset: 0x000BC634
		private bool ConditionsHold(Hero issueGiver)
		{
			if (!issueGiver.IsKingdomLeader)
			{
				Clan clan = issueGiver.Clan;
				if (((clan != null) ? clan.Leader : null) != issueGiver)
				{
					return false;
				}
			}
			if (!issueGiver.IsMinorFactionHero && issueGiver.Clan != Clan.PlayerClan)
			{
				MobileParty partyBelongedTo = issueGiver.PartyBelongedTo;
				if (partyBelongedTo != null && partyBelongedTo.Party.MemberRoster.TotalManCount > 50)
				{
					int num2;
					float num = LordNeedsHorsesIssueBehavior.ComputeMountsOverInfantryCountRatio(partyBelongedTo, out num2);
					return num2 >= 10 && num < 0.6f;
				}
			}
			return false;
		}

		// Token: 0x06002D75 RID: 11637 RVA: 0x000BE4AC File Offset: 0x000BC6AC
		public static float ComputeMountsOverInfantryCountRatio(MobileParty issueParty, out int numInfantry)
		{
			if (issueParty == null)
			{
				Debug.FailedAssert("Cannot compute mounts over infantry ratio as related party is null", "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\Issues\\LordNeedsHorsesIssueBehavior.cs", "ComputeMountsOverInfantryCountRatio", 919);
				numInfantry = 0;
				return float.MaxValue;
			}
			int numberOfMounts = issueParty.ItemRoster.NumberOfMounts;
			numInfantry = 0;
			foreach (TroopRosterElement troopRosterElement in issueParty.Party.MemberRoster.GetTroopRoster())
			{
				if (troopRosterElement.Character.IsInfantry)
				{
					numInfantry += troopRosterElement.Number;
				}
			}
			if (numInfantry != 0)
			{
				return (float)numberOfMounts / (float)numInfantry;
			}
			return float.MaxValue;
		}

		// Token: 0x06002D76 RID: 11638 RVA: 0x000BE560 File Offset: 0x000BC760
		public static bool IsMountCamel(ItemObject mountObject)
		{
			HorseComponent horseComponent;
			return (horseComponent = (((mountObject != null) ? mountObject.ItemComponent : null) as HorseComponent)) != null && horseComponent.Monster.MonsterUsage == "camel";
		}

		// Token: 0x06002D77 RID: 11639 RVA: 0x000BE599 File Offset: 0x000BC799
		public override void RegisterEvents()
		{
			CampaignEvents.OnCheckForIssueEvent.AddNonSerializedListener(this, new Action<Hero>(this.OnCheckForIssue));
		}

		// Token: 0x06002D78 RID: 11640 RVA: 0x000BE5B2 File Offset: 0x000BC7B2
		public override void SyncData(IDataStore dataStore)
		{
		}

		// Token: 0x04000D99 RID: 3481
		private const IssueBase.IssueFrequency LordNeedsHorsesIssueFrequency = IssueBase.IssueFrequency.VeryCommon;

		// Token: 0x0200064D RID: 1613
		public class LordNeedsHorsesIssue : IssueBase
		{
			// Token: 0x0600503C RID: 20540 RVA: 0x0016DC45 File Offset: 0x0016BE45
			internal static void AutoGeneratedStaticCollectObjectsLordNeedsHorsesIssue(object o, List<object> collectedObjects)
			{
				((LordNeedsHorsesIssueBehavior.LordNeedsHorsesIssue)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x0600503D RID: 20541 RVA: 0x0016DC53 File Offset: 0x0016BE53
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
				collectedObjects.Add(this._mountObjectToBeDelivered);
			}

			// Token: 0x0600503E RID: 20542 RVA: 0x0016DC68 File Offset: 0x0016BE68
			internal static object AutoGeneratedGetMemberValue_numMountsToBeDelivered(object o)
			{
				return ((LordNeedsHorsesIssueBehavior.LordNeedsHorsesIssue)o)._numMountsToBeDelivered;
			}

			// Token: 0x0600503F RID: 20543 RVA: 0x0016DC7A File Offset: 0x0016BE7A
			internal static object AutoGeneratedGetMemberValue_mountObjectToBeDelivered(object o)
			{
				return ((LordNeedsHorsesIssueBehavior.LordNeedsHorsesIssue)o)._mountObjectToBeDelivered;
			}

			// Token: 0x06005040 RID: 20544 RVA: 0x0016DC87 File Offset: 0x0016BE87
			internal static object AutoGeneratedGetMemberValue_mountValuePerUnit(object o)
			{
				return ((LordNeedsHorsesIssueBehavior.LordNeedsHorsesIssue)o)._mountValuePerUnit;
			}

			// Token: 0x170010CA RID: 4298
			// (get) Token: 0x06005041 RID: 20545 RVA: 0x0016DC99 File Offset: 0x0016BE99
			protected override int AlternativeSolutionBaseDurationInDaysInternal
			{
				get
				{
					return 2 + MathF.Ceiling(4f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x170010CB RID: 4299
			// (get) Token: 0x06005042 RID: 20546 RVA: 0x0016DCAE File Offset: 0x0016BEAE
			public override IssueBase.AlternativeSolutionScaleFlag AlternativeSolutionScaleFlags
			{
				get
				{
					return IssueBase.AlternativeSolutionScaleFlag.Duration;
				}
			}

			// Token: 0x170010CC RID: 4300
			// (get) Token: 0x06005043 RID: 20547 RVA: 0x0016DCB1 File Offset: 0x0016BEB1
			protected override int RewardGold
			{
				get
				{
					return 500 + MathF.Ceiling(1.5f * (float)this.IssueNumMountsToBeDelivered * (float)this._mountValuePerUnit);
				}
			}

			// Token: 0x170010CD RID: 4301
			// (get) Token: 0x06005044 RID: 20548 RVA: 0x0016DCD3 File Offset: 0x0016BED3
			private int IssueNumMountsToBeDelivered
			{
				get
				{
					if (this._numMountsToBeDelivered == 0)
					{
						this._numMountsToBeDelivered = 1 + MathF.Ceiling(12f * base.IssueDifficultyMultiplier);
					}
					return this._numMountsToBeDelivered;
				}
			}

			// Token: 0x170010CE RID: 4302
			// (get) Token: 0x06005045 RID: 20549 RVA: 0x0016DCFC File Offset: 0x0016BEFC
			public override int AlternativeSolutionBaseNeededMenCount
			{
				get
				{
					return 3 + MathF.Ceiling(6f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x170010CF RID: 4303
			// (get) Token: 0x06005046 RID: 20550 RVA: 0x0016DD11 File Offset: 0x0016BF11
			private int AlternativeSolutionGoldRequirement
			{
				get
				{
					return this.IssueNumMountsToBeDelivered * this._mountValuePerUnit;
				}
			}

			// Token: 0x170010D0 RID: 4304
			// (get) Token: 0x06005047 RID: 20551 RVA: 0x0016DD20 File Offset: 0x0016BF20
			protected override int CompanionSkillRewardXP
			{
				get
				{
					return (int)(500f + 700f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x170010D1 RID: 4305
			// (get) Token: 0x06005048 RID: 20552 RVA: 0x0016DD35 File Offset: 0x0016BF35
			public override TextObject IssueBriefByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=TBpMffcv}Campaigning this season has taken even a higher toll on {?MOUNT_TYPE_IS_CAMEL}camels{?}horses{\\?} than it has on my men. The animals will drop dead of exhaustion while my troops soldier on. Yet if we don't keep our stocks up, the enemy will run rings around us.[if:convo_undecided_closed][ib:closed]", null);
					textObject.SetTextVariable("MOUNT_TYPE_IS_CAMEL", LordNeedsHorsesIssueBehavior.IsMountCamel(this._mountObjectToBeDelivered) ? 1 : 0);
					return textObject;
				}
			}

			// Token: 0x170010D2 RID: 4306
			// (get) Token: 0x06005049 RID: 20553 RVA: 0x0016DD5F File Offset: 0x0016BF5F
			public override TextObject IssueAcceptByPlayer
			{
				get
				{
					TextObject textObject = new TextObject("{=jjNSVzx3}What do you need, my {?ISSUE_GIVER.GENDER}lady{?}lord{\\?}?", null);
					textObject.SetCharacterProperties("ISSUE_GIVER", base.IssueOwner.CharacterObject, false);
					return textObject;
				}
			}

			// Token: 0x170010D3 RID: 4307
			// (get) Token: 0x0600504A RID: 20554 RVA: 0x0016DD84 File Offset: 0x0016BF84
			public override TextObject IssueQuestSolutionExplanationByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=ugHO6Sa6}I need more {?MOUNT_TYPE_IS_CAMEL}camels{?}horses{\\?}, specifically, we need {MOUNT_COUNT} and they need to be {PLURAL(MOUNT_NAME)}, because we know how to use them and how they fit our needs. Bring them to me and a bag of {REWARD}{GOLD_ICON} will be right in your pocket.[if:convo_undecided_closed]", null);
					textObject.SetTextVariable("MOUNT_TYPE_IS_CAMEL", LordNeedsHorsesIssueBehavior.IsMountCamel(this._mountObjectToBeDelivered) ? 1 : 0);
					textObject.SetTextVariable("MOUNT_COUNT", this.IssueNumMountsToBeDelivered);
					textObject.SetTextVariable("REWARD", this.RewardGold);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					textObject.SetTextVariable("MOUNT_NAME", this._mountObjectToBeDelivered.Name);
					return textObject;
				}
			}

			// Token: 0x170010D4 RID: 4308
			// (get) Token: 0x0600504B RID: 20555 RVA: 0x0016DE05 File Offset: 0x0016C005
			public override TextObject IssueQuestSolutionAcceptByPlayer
			{
				get
				{
					TextObject textObject = new TextObject("{=0YRl5Yie}I'll bring your {?MOUNT_TYPE_IS_CAMEL}camels{?}horses{\\?} by myself.", null);
					textObject.SetTextVariable("MOUNT_TYPE_IS_CAMEL", LordNeedsHorsesIssueBehavior.IsMountCamel(this._mountObjectToBeDelivered) ? 1 : 0);
					return textObject;
				}
			}

			// Token: 0x170010D5 RID: 4309
			// (get) Token: 0x0600504C RID: 20556 RVA: 0x0016DE2F File Offset: 0x0016C02F
			public override bool IsThereAlternativeSolution
			{
				get
				{
					return true;
				}
			}

			// Token: 0x170010D6 RID: 4310
			// (get) Token: 0x0600504D RID: 20557 RVA: 0x0016DE34 File Offset: 0x0016C034
			public override TextObject IssueAlternativeSolutionExplanationByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=YHG17dqZ}One of your companions who is good at haggling and riding would be appropriate for this task. {?MOUNT_TYPE_IS_CAMEL}Camels{?}Horses{\\?} should cost no more than {REQUIRED_GOLD_AMOUNT}{GOLD_ICON} denars and this should be covered by yourself. You'll also need some cavalry to bring the {?MOUNT_TYPE_IS_CAMEL}camels{?}horses{\\?}. A purse of {REWARD_GOLD_AMOUNT}{GOLD_ICON} denars will be waiting for you when you get the job done.[if:convo_undecided_closed]", null);
					textObject.SetTextVariable("MOUNT_TYPE_IS_CAMEL", LordNeedsHorsesIssueBehavior.IsMountCamel(this._mountObjectToBeDelivered) ? 1 : 0);
					textObject.SetTextVariable("REQUIRED_GOLD_AMOUNT", this.AlternativeSolutionGoldRequirement);
					textObject.SetTextVariable("REWARD_GOLD_AMOUNT", this.RewardGold);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x170010D7 RID: 4311
			// (get) Token: 0x0600504E RID: 20558 RVA: 0x0016DE9E File Offset: 0x0016C09E
			public override TextObject IssueAlternativeSolutionAcceptByPlayer
			{
				get
				{
					TextObject textObject = new TextObject("{=loJja04L}My men will bring your {?MOUNT_TYPE_IS_CAMEL}camels{?}horses{\\?} as soon as possible.", null);
					textObject.SetTextVariable("MOUNT_TYPE_IS_CAMEL", LordNeedsHorsesIssueBehavior.IsMountCamel(this._mountObjectToBeDelivered) ? 1 : 0);
					return textObject;
				}
			}

			// Token: 0x170010D8 RID: 4312
			// (get) Token: 0x0600504F RID: 20559 RVA: 0x0016DEC8 File Offset: 0x0016C0C8
			public override TextObject IssueDiscussAlternativeSolution
			{
				get
				{
					return new TextObject("{=6EJbUGpi}You will be rewarded when your companion returns with the animals we discussed.[if:convo_approving]", null);
				}
			}

			// Token: 0x170010D9 RID: 4313
			// (get) Token: 0x06005050 RID: 20560 RVA: 0x0016DED5 File Offset: 0x0016C0D5
			public override TextObject IssueAlternativeSolutionResponseByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=YF6PPWlT}Very good. I'm sure your men will bring my {?MOUNT_TYPE_IS_CAMEL}camels{?}horses{\\?} as soon as possible.[if:convo_approving]", null);
					textObject.SetTextVariable("MOUNT_TYPE_IS_CAMEL", LordNeedsHorsesIssueBehavior.IsMountCamel(this._mountObjectToBeDelivered) ? 1 : 0);
					return textObject;
				}
			}

			// Token: 0x170010DA RID: 4314
			// (get) Token: 0x06005051 RID: 20561 RVA: 0x0016DF00 File Offset: 0x0016C100
			protected override TextObject AlternativeSolutionStartLog
			{
				get
				{
					TextObject textObject = new TextObject("{=PCigQKQ8}{QUEST_GIVER.LINK} told you that {?QUEST_GIVER.GENDER}she{?}he{\\?} needs {?MOUNT_TYPE_IS_CAMEL}camels{?}horses{\\?} for {?QUEST_GIVER.GENDER}her{?}his{\\?} party. You asked your companion {COMPANION.LINK} and {TROOP_COUNT} of your horsemen to deliver {MOUNT_COUNT} {PLURAL(MOUNT_NAME)} to {QUEST_GIVER.LINK}. {?QUEST_GIVER.GENDER}She{?}He{\\?} will pay you {REWARD}{GOLD_ICON} denars when the task is done. They will rejoin your party in {RETURN_DAYS} days.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.IssueOwner.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("COMPANION", base.AlternativeSolutionHero.CharacterObject, textObject, false);
					textObject.SetTextVariable("MOUNT_TYPE_IS_CAMEL", LordNeedsHorsesIssueBehavior.IsMountCamel(this._mountObjectToBeDelivered) ? 1 : 0);
					textObject.SetTextVariable("REWARD", this.RewardGold);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					textObject.SetTextVariable("TROOP_COUNT", this.AlternativeSolutionSentTroops.TotalManCount - 1);
					textObject.SetTextVariable("MOUNT_COUNT", this.IssueNumMountsToBeDelivered);
					textObject.SetTextVariable("MOUNT_NAME", this._mountObjectToBeDelivered.Name);
					textObject.SetTextVariable("RETURN_DAYS", MathF.Ceiling(base.AlternativeSolutionReturnTimeForTroops.RemainingDaysFromNow));
					return textObject;
				}
			}

			// Token: 0x170010DB RID: 4315
			// (get) Token: 0x06005052 RID: 20562 RVA: 0x0016DFEC File Offset: 0x0016C1EC
			public override TextObject IssueAlternativeSolutionSuccessLog
			{
				get
				{
					TextObject textObject = new TextObject("{=tJc5mZua}Your companion has successfully delivered the {?MOUNT_TYPE_IS_CAMEL}camels{?}horses{\\?} {QUEST_GIVER.LINK} requested. You received {QUEST_REWARD}{GOLD_ICON} gold in return for your service.", null);
					textObject.SetTextVariable("MOUNT_TYPE_IS_CAMEL", LordNeedsHorsesIssueBehavior.IsMountCamel(this._mountObjectToBeDelivered) ? 1 : 0);
					textObject.SetTextVariable("QUEST_REWARD", this.RewardGold);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.IssueOwner.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x170010DC RID: 4316
			// (get) Token: 0x06005053 RID: 20563 RVA: 0x0016E05E File Offset: 0x0016C25E
			public override bool IsThereLordSolution
			{
				get
				{
					return false;
				}
			}

			// Token: 0x06005054 RID: 20564 RVA: 0x0016E061 File Offset: 0x0016C261
			public override bool DoTroopsSatisfyAlternativeSolution(TroopRoster troopRoster, out TextObject explanation)
			{
				explanation = TextObject.Empty;
				return QuestHelper.CheckRosterForAlternativeSolution(troopRoster, base.GetTotalAlternativeSolutionNeededMenCount(), ref explanation, 2, true);
			}

			// Token: 0x06005055 RID: 20565 RVA: 0x0016E079 File Offset: 0x0016C279
			public override bool IsTroopTypeNeededByAlternativeSolution(CharacterObject character)
			{
				return character.Tier >= 2 && character.IsMounted;
			}

			// Token: 0x06005056 RID: 20566 RVA: 0x0016E08C File Offset: 0x0016C28C
			public override bool AlternativeSolutionCondition(out TextObject explanation)
			{
				explanation = TextObject.Empty;
				return QuestHelper.CheckRosterForAlternativeSolution(MobileParty.MainParty.MemberRoster, base.GetTotalAlternativeSolutionNeededMenCount(), ref explanation, 2, true) && QuestHelper.CheckGoldForAlternativeSolution(this.AlternativeSolutionGoldRequirement, ref explanation);
			}

			// Token: 0x06005057 RID: 20567 RVA: 0x0016E0BD File Offset: 0x0016C2BD
			public override void AlternativeSolutionStartConsequence()
			{
				Hero.MainHero.ChangeHeroGold(-this.AlternativeSolutionGoldRequirement);
			}

			// Token: 0x06005058 RID: 20568 RVA: 0x0016E0D0 File Offset: 0x0016C2D0
			protected override void AlternativeSolutionEndWithSuccessConsequence()
			{
				this.RelationshipChangeWithIssueOwner = 2;
				GainRenownAction.Apply(Hero.MainHero, 1f, false);
			}

			// Token: 0x06005059 RID: 20569 RVA: 0x0016E0E9 File Offset: 0x0016C2E9
			protected override void AlternativeSolutionEndWithFailureConsequence()
			{
				this.RelationshipChangeWithIssueOwner = -5;
			}

			// Token: 0x0600505A RID: 20570 RVA: 0x0016E0F3 File Offset: 0x0016C2F3
			protected override void OnGameLoad()
			{
			}

			// Token: 0x0600505B RID: 20571 RVA: 0x0016E0F5 File Offset: 0x0016C2F5
			protected override void HourlyTick()
			{
			}

			// Token: 0x0600505C RID: 20572 RVA: 0x0016E0F7 File Offset: 0x0016C2F7
			protected override QuestBase GenerateIssueQuest(string questId)
			{
				return new LordNeedsHorsesIssueBehavior.LordNeedsHorsesIssueQuest(questId, base.IssueOwner, this.IssueNumMountsToBeDelivered, this._mountObjectToBeDelivered, this.RewardGold, CampaignTime.DaysFromNow(20f));
			}

			// Token: 0x0600505D RID: 20573 RVA: 0x0016E121 File Offset: 0x0016C321
			public override IssueBase.IssueFrequency GetFrequency()
			{
				return IssueBase.IssueFrequency.VeryCommon;
			}

			// Token: 0x0600505E RID: 20574 RVA: 0x0016E124 File Offset: 0x0016C324
			protected override bool CanPlayerTakeQuestConditions(Hero issueGiver, out IssueBase.PreconditionFlags flag, out Hero relationHero, out SkillObject skill)
			{
				flag = IssueBase.PreconditionFlags.None;
				skill = null;
				relationHero = null;
				if (issueGiver.GetRelationWithPlayer() < -10f)
				{
					relationHero = issueGiver;
					flag |= IssueBase.PreconditionFlags.Relation;
				}
				if (Hero.MainHero.IsKingdomLeader)
				{
					flag |= IssueBase.PreconditionFlags.MainHeroIsKingdomLeader;
				}
				if (issueGiver.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction))
				{
					flag |= IssueBase.PreconditionFlags.AtWar;
				}
				return flag == IssueBase.PreconditionFlags.None;
			}

			// Token: 0x0600505F RID: 20575 RVA: 0x0016E18A File Offset: 0x0016C38A
			protected override void CompleteIssueWithTimedOutConsequences()
			{
			}

			// Token: 0x06005060 RID: 20576 RVA: 0x0016E18C File Offset: 0x0016C38C
			public override bool IssueStayAliveConditions()
			{
				int num;
				return !base.IssueOwner.IsDead && base.IssueOwner.PartyBelongedTo != null && base.IssueOwner.Clan != Clan.PlayerClan && (base.IssueOwner.IsKingdomLeader || base.IssueOwner.Clan.Leader == base.IssueOwner) && LordNeedsHorsesIssueBehavior.ComputeMountsOverInfantryCountRatio(base.IssueOwner.PartyBelongedTo, out num) < 0.8f;
			}

			// Token: 0x170010DD RID: 4317
			// (get) Token: 0x06005061 RID: 20577 RVA: 0x0016E206 File Offset: 0x0016C406
			public override TextObject Title
			{
				get
				{
					TextObject textObject = new TextObject("{=5zF6vI5s}Lord Needs {?MOUNT_TYPE_IS_CAMEL}Camels{?}Horses{\\?}", null);
					textObject.SetTextVariable("MOUNT_TYPE_IS_CAMEL", LordNeedsHorsesIssueBehavior.IsMountCamel(this._mountObjectToBeDelivered) ? 1 : 0);
					return textObject;
				}
			}

			// Token: 0x170010DE RID: 4318
			// (get) Token: 0x06005062 RID: 20578 RVA: 0x0016E230 File Offset: 0x0016C430
			public override TextObject Description
			{
				get
				{
					TextObject textObject = new TextObject("{=GHbM1i6R}{QUEST_GIVER.LINK} needs {?MOUNT_TYPE_IS_CAMEL}camels{?}horses{\\?} to speed up {?QUEST_GIVER.GENDER}her{?}his{\\?} party.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.IssueOwner.CharacterObject, textObject, false);
					textObject.SetTextVariable("MOUNT_TYPE_IS_CAMEL", LordNeedsHorsesIssueBehavior.IsMountCamel(this._mountObjectToBeDelivered) ? 1 : 0);
					return textObject;
				}
			}

			// Token: 0x06005063 RID: 20579 RVA: 0x0016E280 File Offset: 0x0016C480
			public LordNeedsHorsesIssue(Hero issueOwner) : base(issueOwner, CampaignTime.DaysFromNow(20f))
			{
				MBList<ItemObject> mblist = new MBList<ItemObject>();
				foreach (ItemObject itemObject in Items.All)
				{
					if (itemObject.IsMountable && itemObject.Culture == issueOwner.Culture && !itemObject.NotMerchandise && itemObject.Tierf > 2f && itemObject.Tierf < 3f)
					{
						mblist.Add(itemObject);
					}
				}
				this._mountObjectToBeDelivered = mblist.GetRandomElement<ItemObject>();
				this._numMountsToBeDelivered = 1 + MathF.Ceiling(12f * base.IssueDifficultyMultiplier);
				if (this._mountObjectToBeDelivered == null)
				{
					this._mountObjectToBeDelivered = MBObjectManager.Instance.GetObject<ItemObject>("sumpter_horse");
				}
				ItemObject mountObjectToBeDelivered = this._mountObjectToBeDelivered;
				this._mountValuePerUnit = ((mountObjectToBeDelivered != null) ? mountObjectToBeDelivered.Value : 0);
			}

			// Token: 0x06005064 RID: 20580 RVA: 0x0016E37C File Offset: 0x0016C57C
			protected override float GetIssueEffectAmountInternal(IssueEffect issueEffect)
			{
				if (issueEffect == DefaultIssueEffects.ClanInfluence)
				{
					return -0.1f;
				}
				return 0f;
			}

			// Token: 0x06005065 RID: 20581 RVA: 0x0016E391 File Offset: 0x0016C591
			public override ValueTuple<SkillObject, int> GetAlternativeSolutionSkill(Hero hero)
			{
				return new ValueTuple<SkillObject, int>((hero.GetSkillValue(DefaultSkills.Trade) >= hero.GetSkillValue(DefaultSkills.Riding)) ? DefaultSkills.Trade : DefaultSkills.Riding, 120);
			}

			// Token: 0x04001A72 RID: 6770
			private const int IssueDueTimeInDays = 20;

			// Token: 0x04001A73 RID: 6771
			internal const int IssueGiverMinimumPartySize = 50;

			// Token: 0x04001A74 RID: 6772
			internal const int IssueGiverMinimumInfantryCount = 10;

			// Token: 0x04001A75 RID: 6773
			internal const float IssuePreConditionMinPlayerRelation = -10f;

			// Token: 0x04001A76 RID: 6774
			internal const float IssuePreConditionMountsOverInfantryRatioThreshold = 0.6f;

			// Token: 0x04001A77 RID: 6775
			internal const float IssueStayingAliveMountsOverInfantryRatioThreshold = 0.8f;

			// Token: 0x04001A78 RID: 6776
			private const int AlternativeSolutionCompanionSkillThreshold = 120;

			// Token: 0x04001A79 RID: 6777
			private const int AlternativeSolutionRenownRewardOnSuccess = 1;

			// Token: 0x04001A7A RID: 6778
			private const int AlternativeSolutionRelationRewardOnSuccess = 2;

			// Token: 0x04001A7B RID: 6779
			private const int AlternativeSolutionRelationPenaltyOnFail = -5;

			// Token: 0x04001A7C RID: 6780
			private const int AlternativeSolutionTroopTierRequirement = 2;

			// Token: 0x04001A7D RID: 6781
			[SaveableField(4)]
			private int _numMountsToBeDelivered;

			// Token: 0x04001A7E RID: 6782
			[SaveableField(2)]
			private readonly ItemObject _mountObjectToBeDelivered;

			// Token: 0x04001A7F RID: 6783
			[SaveableField(3)]
			private readonly int _mountValuePerUnit;
		}

		// Token: 0x0200064E RID: 1614
		public class LordNeedsHorsesIssueQuest : QuestBase
		{
			// Token: 0x06005066 RID: 20582 RVA: 0x0016E3BE File Offset: 0x0016C5BE
			internal static void AutoGeneratedStaticCollectObjectsLordNeedsHorsesIssueQuest(object o, List<object> collectedObjects)
			{
				((LordNeedsHorsesIssueBehavior.LordNeedsHorsesIssueQuest)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x06005067 RID: 20583 RVA: 0x0016E3CC File Offset: 0x0016C5CC
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
				collectedObjects.Add(this._mountObjectToBeDelivered);
				collectedObjects.Add(this._questJournalEntry);
			}

			// Token: 0x06005068 RID: 20584 RVA: 0x0016E3ED File Offset: 0x0016C5ED
			internal static object AutoGeneratedGetMemberValue_numMountsToBeDelivered(object o)
			{
				return ((LordNeedsHorsesIssueBehavior.LordNeedsHorsesIssueQuest)o)._numMountsToBeDelivered;
			}

			// Token: 0x06005069 RID: 20585 RVA: 0x0016E3FF File Offset: 0x0016C5FF
			internal static object AutoGeneratedGetMemberValue_mountObjectToBeDelivered(object o)
			{
				return ((LordNeedsHorsesIssueBehavior.LordNeedsHorsesIssueQuest)o)._mountObjectToBeDelivered;
			}

			// Token: 0x0600506A RID: 20586 RVA: 0x0016E40C File Offset: 0x0016C60C
			internal static object AutoGeneratedGetMemberValue_questJournalEntry(object o)
			{
				return ((LordNeedsHorsesIssueBehavior.LordNeedsHorsesIssueQuest)o)._questJournalEntry;
			}

			// Token: 0x170010DF RID: 4319
			// (get) Token: 0x0600506B RID: 20587 RVA: 0x0016E419 File Offset: 0x0016C619
			public override TextObject Title
			{
				get
				{
					TextObject textObject = new TextObject("{=5zF6vI5s}Lord Needs {?MOUNT_TYPE_IS_CAMEL}Camels{?}Horses{\\?}", null);
					textObject.SetTextVariable("MOUNT_TYPE_IS_CAMEL", LordNeedsHorsesIssueBehavior.IsMountCamel(this._mountObjectToBeDelivered) ? 1 : 0);
					return textObject;
				}
			}

			// Token: 0x170010E0 RID: 4320
			// (get) Token: 0x0600506C RID: 20588 RVA: 0x0016E443 File Offset: 0x0016C643
			private TextObject _journalTaskName
			{
				get
				{
					TextObject textObject = new TextObject("{=plHZYtxF}{PLURAL(REQUESTED_MOUNT_NAME)} in Inventory: ", null);
					textObject.SetTextVariable("REQUESTED_MOUNT_NAME", this._mountObjectToBeDelivered.Name);
					return textObject;
				}
			}

			// Token: 0x170010E1 RID: 4321
			// (get) Token: 0x0600506D RID: 20589 RVA: 0x0016E468 File Offset: 0x0016C668
			private TextObject _onQuestStartedLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=GQ96SX4M}{QUEST_GIVER.LINK} told you that {?QUEST_GIVER.GENDER}she{?}he{\\?} needs {?MOUNT_TYPE_IS_CAMEL}camels{?}horses{\\?} for {?QUEST_GIVER.GENDER}her{?}his{\\?} party. {?QUEST_GIVER.GENDER}She{?}He{\\?} asked you to bring {MOUNT_COUNT} {PLURAL(MOUNT_NAME)} to {?QUEST_GIVER.GENDER}her{?}him{\\?} or one of {?QUEST_GIVER.GENDER}her{?}his{\\?} garrison commanders. {?QUEST_GIVER.GENDER}She{?}He{\\?} will pay you {REWARD_GOLD}{GOLD_ICON} denars when the task is done.", null);
					textObject.SetTextVariable("MOUNT_TYPE_IS_CAMEL", LordNeedsHorsesIssueBehavior.IsMountCamel(this._mountObjectToBeDelivered) ? 1 : 0);
					textObject.SetTextVariable("MOUNT_COUNT", this._numMountsToBeDelivered);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					textObject.SetTextVariable("MOUNT_NAME", this._mountObjectToBeDelivered.Name);
					textObject.SetTextVariable("REWARD_GOLD", this.RewardGold);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x170010E2 RID: 4322
			// (get) Token: 0x0600506E RID: 20590 RVA: 0x0016E504 File Offset: 0x0016C704
			private TextObject _onQuestSucceededLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=aGvLxsub}You have successfully delivered {MOUNT_COUNT} {PLURAL(MOUNT_NAME)} to {QUEST_GIVER.LINK} as requested. You received {GOLD_REWARD}{GOLD_ICON} denars in return for your service.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("MOUNT_COUNT", this._numMountsToBeDelivered);
					textObject.SetTextVariable("MOUNT_NAME", this._mountObjectToBeDelivered.Name);
					textObject.SetTextVariable("GOLD_REWARD", this.RewardGold);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x170010E3 RID: 4323
			// (get) Token: 0x0600506F RID: 20591 RVA: 0x0016E584 File Offset: 0x0016C784
			private TextObject _onQuestFailedLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=yLuzvTtd}You had promised to deliver {MOUNT_COUNT} {PLURAL(MOUNT_NAME)} to {QUEST_GIVER.LINK}. But you've failed to complete this task. {QUEST_GIVER.LINK} was displeased.", null);
					textObject.SetTextVariable("MOUNT_COUNT", this._numMountsToBeDelivered);
					textObject.SetTextVariable("MOUNT_NAME", this._mountObjectToBeDelivered.Name);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x170010E4 RID: 4324
			// (get) Token: 0x06005070 RID: 20592 RVA: 0x0016E5E0 File Offset: 0x0016C7E0
			private TextObject _onQuestTimedOutLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=BFEYIMdi}You had promised to deliver {MOUNT_COUNT} {PLURAL(MOUNT_NAME)} to {QUEST_GIVER.LINK}. But you've failed to complete this task in time. {QUEST_GIVER.LINK} was displeased.", null);
					textObject.SetTextVariable("MOUNT_COUNT", this._numMountsToBeDelivered);
					textObject.SetTextVariable("MOUNT_NAME", this._mountObjectToBeDelivered.Name);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x170010E5 RID: 4325
			// (get) Token: 0x06005071 RID: 20593 RVA: 0x0016E63C File Offset: 0x0016C83C
			private TextObject _onQuestCancelled2LogText
			{
				get
				{
					TextObject textObject = new TextObject("{=pYgl86Cr}Your clan had entered a war with the {QUEST_GIVER.LINK}'s faction. Your agreement was canceled. You can no longer deliver the {?MOUNT_TYPE_IS_CAMEL}camels{?}horses{\\?} to {?QUEST_GIVER.GENDER}her{?}him{\\?}.", null);
					textObject.SetTextVariable("MOUNT_TYPE_IS_CAMEL", LordNeedsHorsesIssueBehavior.IsMountCamel(this._mountObjectToBeDelivered) ? 1 : 0);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x170010E6 RID: 4326
			// (get) Token: 0x06005072 RID: 20594 RVA: 0x0016E68C File Offset: 0x0016C88C
			private TextObject _playerDeclaredWarQuestLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=bqeWVVEE}Your actions have started a war with {QUEST_GIVER.LINK}'s faction. {?QUEST_GIVER.GENDER}She{?}He{\\?} cancels your agreement and the quest is a failure.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x170010E7 RID: 4327
			// (get) Token: 0x06005073 RID: 20595 RVA: 0x0016E6C0 File Offset: 0x0016C8C0
			private TextObject _onQuestCancelled3LogText
			{
				get
				{
					TextObject textObject = new TextObject("{=qEh4gdjU}{QUEST_GIVER.LINK} was imprisoned and your agreement with {?QUEST_GIVER.GENDER}her{?}him{\\?} was canceled. You can no longer deliver the {?MOUNT_TYPE_IS_CAMEL}camels{?}horses{\\?} to {?QUEST_GIVER.GENDER}her{?}him{\\?}.", null);
					textObject.SetTextVariable("MOUNT_TYPE_IS_CAMEL", LordNeedsHorsesIssueBehavior.IsMountCamel(this._mountObjectToBeDelivered) ? 1 : 0);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x170010E8 RID: 4328
			// (get) Token: 0x06005074 RID: 20596 RVA: 0x0016E710 File Offset: 0x0016C910
			private TextObject _onQuestMountRequirementSatisfiedQuickText
			{
				get
				{
					TextObject textObject = new TextObject("{=ZCPrYXaO}You have enough {?MOUNT_TYPE_IS_CAMEL}camels{?}horses{\\?}. Return back to {QUEST_GIVER.LINK}.", null);
					textObject.SetTextVariable("MOUNT_TYPE_IS_CAMEL", LordNeedsHorsesIssueBehavior.IsMountCamel(this._mountObjectToBeDelivered) ? 1 : 0);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x170010E9 RID: 4329
			// (get) Token: 0x06005075 RID: 20597 RVA: 0x0016E760 File Offset: 0x0016C960
			private TextObject _onQuestMountRequirementNotSatisfiedQuickText
			{
				get
				{
					TextObject textObject = new TextObject("{=aFNfxhwz}You no longer have enough {?MOUNT_TYPE_IS_CAMEL}camels{?}horses{\\?} for {QUEST_GIVER.LINK}.", null);
					textObject.SetTextVariable("MOUNT_TYPE_IS_CAMEL", LordNeedsHorsesIssueBehavior.IsMountCamel(this._mountObjectToBeDelivered) ? 1 : 0);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x170010EA RID: 4330
			// (get) Token: 0x06005076 RID: 20598 RVA: 0x0016E7AF File Offset: 0x0016C9AF
			public override bool IsRemainingTimeHidden
			{
				get
				{
					return false;
				}
			}

			// Token: 0x06005077 RID: 20599 RVA: 0x0016E7B4 File Offset: 0x0016C9B4
			public LordNeedsHorsesIssueQuest(string questId, Hero questGiver, int numMountsToBeDelivered, ItemObject mountObjectToBeDelivered, int rewardGold, CampaignTime duration) : base(questId, questGiver, duration, rewardGold)
			{
				this._numMountsToBeDelivered = numMountsToBeDelivered;
				this._mountObjectToBeDelivered = mountObjectToBeDelivered;
				this._playerInventoryVersionNo = MobileParty.MainParty.ItemRoster.VersionNo;
				this._questGiversAgentCharacterObject = null;
				base.AddTrackedObject(base.QuestGiver);
				this.SetDialogs();
				base.InitializeQuestOnCreation();
			}

			// Token: 0x06005078 RID: 20600 RVA: 0x0016E810 File Offset: 0x0016CA10
			protected override void InitializeQuestOnGameLoad()
			{
				this.SetDialogs();
				this._numMountsInInventory = this.GetNumQuestMountsInInventory();
				this._playerInventoryVersionNo = MobileParty.MainParty.ItemRoster.VersionNo;
				if (this._questJournalEntry == null)
				{
					this._questJournalEntry = base.JournalEntries.FirstOrDefault((JournalLog x) => x.Range == this._numMountsToBeDelivered && x.Type == LogType.Discreate);
					if (this._questJournalEntry == null)
					{
						if (base.JournalEntries.Count > 0)
						{
							for (int i = 0; i < base.JournalEntries.Count; i++)
							{
								if (base.JournalEntries[i].Type == LogType.Discreate)
								{
									base.RemoveLog(base.JournalEntries[i]);
								}
							}
							this._questJournalEntry = base.AddDiscreteLog(this._onQuestStartedLogText, this._journalTaskName, MBMath.ClampInt(this._numMountsInInventory, 0, this._numMountsToBeDelivered), this._numMountsToBeDelivered, null, false);
						}
						else
						{
							this._questJournalEntry = base.AddDiscreteLog(this._onQuestStartedLogText, this._journalTaskName, MBMath.ClampInt(this._numMountsInInventory, 0, this._numMountsToBeDelivered), this._numMountsToBeDelivered, null, false);
						}
					}
				}
				this.UpdateQuestJournalEntry();
			}

			// Token: 0x06005079 RID: 20601 RVA: 0x0016E930 File Offset: 0x0016CB30
			protected override void SetDialogs()
			{
				Campaign.Current.ConversationManager.AddDialogFlow(this.GetGarrisonCommanderDialogFlow(), this);
				this.OfferDialogFlow = DialogFlow.CreateDialogFlow("issue_classic_quest_start", 100).NpcLine("{=qR3gQrLi}Splendid. We'll need to keep moving around, though, so it might be tricky to find us. My fellow nobles will usually know where to find me though, if you ask them.[if:convo_approving][ib:hip2]", null, null).Condition(() => Hero.OneToOneConversationHero == base.QuestGiver).Consequence(new ConversationSentence.OnConsequenceDelegate(this.OnQuestAccepted)).CloseDialog();
				new TextObject(LordNeedsHorsesIssueBehavior.IsMountCamel(this._mountObjectToBeDelivered) ? "{=nysBXpEO}camels" : "{=6YbGQDme}horses", null);
				TextObject textObject = new TextObject("{=bmW77NvO}What about my {?MOUNT_TYPE_IS_CAMEL}camels{?}horses{\\?}?", null);
				textObject.SetTextVariable("MOUNT_TYPE_IS_CAMEL", LordNeedsHorsesIssueBehavior.IsMountCamel(this._mountObjectToBeDelivered) ? 1 : 0);
				TextObject textObject2 = new TextObject("{=TLcnbALt}Here are your {?MOUNT_TYPE_IS_CAMEL}camels{?}horses{\\?} my {?QUEST_GIVER.GENDER}lady{?}lord{\\?}.", null);
				textObject2.SetTextVariable("MOUNT_TYPE_IS_CAMEL", LordNeedsHorsesIssueBehavior.IsMountCamel(this._mountObjectToBeDelivered) ? 1 : 0);
				StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, textObject2, false);
				StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject2, false);
				TextObject textObject3 = new TextObject("{=6bt9jYai}I am still looking for the {?MOUNT_TYPE_IS_CAMEL}camels{?}horses{\\?} you have requested.", null);
				textObject3.SetTextVariable("MOUNT_TYPE_IS_CAMEL", LordNeedsHorsesIssueBehavior.IsMountCamel(this._mountObjectToBeDelivered) ? 1 : 0);
				TextObject textObject4 = new TextObject("{=pV7DLTAu}I am sorry, my {?QUEST_GIVER.GENDER}lady{?}lord{\\?}. I cannot deliver the {?MOUNT_TYPE_IS_CAMEL}camels{?}horses{\\?} you requested.", null);
				textObject4.SetTextVariable("MOUNT_TYPE_IS_CAMEL", LordNeedsHorsesIssueBehavior.IsMountCamel(this._mountObjectToBeDelivered) ? 1 : 0);
				StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject4, false);
				TextObject textObject5 = new TextObject("{=inkr6Dzy}Too bad. Perhaps someone else will be able to get me the {?MOUNT_TYPE_IS_CAMEL}camels{?}horses{\\?} that I need.", null);
				textObject5.SetTextVariable("MOUNT_TYPE_IS_CAMEL", LordNeedsHorsesIssueBehavior.IsMountCamel(this._mountObjectToBeDelivered) ? 1 : 0);
				this.DiscussDialogFlow = DialogFlow.CreateDialogFlow("quest_discuss", 100).NpcLine(textObject, null, null).Condition(() => Hero.OneToOneConversationHero == base.QuestGiver).Consequence(delegate
				{
					Campaign.Current.ConversationManager.ConversationEndOneShot += MapEventHelper.OnConversationEnd;
				}).BeginPlayerOptions().PlayerOption(textObject2, null).Condition(() => this.GetNumQuestMountsInInventory() >= this._numMountsToBeDelivered).NpcLine("{=9HJbLneH}Thank you for your help, {PLAYER.NAME}. Here is the purse I promised you. Farewell.[if:convo_happy][ib:hip]", null, null).Consequence(new ConversationSentence.OnConsequenceDelegate(base.CompleteQuestWithSuccess)).CloseDialog().PlayerOption(textObject3, null).NpcLine("{=cH0iAEfq}Please take care of this as quickly as you can. I need those animals.[if:convo_undecided_closed]", null, null).CloseDialog().PlayerOption(textObject4, null).NpcLine(textObject5, null, null).Consequence(delegate
				{
					this.OnQuestDeclined();
				}).CloseDialog().EndPlayerOptions();
			}

			// Token: 0x0600507A RID: 20602 RVA: 0x0016EB9C File Offset: 0x0016CD9C
			private DialogFlow GetGarrisonCommanderDialogFlow()
			{
				TextObject textObject = new TextObject("{=JxhEOqyT}We were waiting for you, {?PLAYER.GENDER}madam{?}sir{\\?}. Have you brought the horses that our {?ISSUE_OWNER.GENDER}lady{?}lord{\\?} requested?", null);
				StringHelpers.SetCharacterProperties("ISSUE_OWNER", base.QuestGiver.CharacterObject, textObject, false);
				return DialogFlow.CreateDialogFlow("start", 300).NpcLine(textObject, null, null).Condition(() => CharacterObject.OneToOneConversationCharacter == this._questGiversAgentCharacterObject).BeginPlayerOptions().PlayerOption(new TextObject("{=ZEy3gE7w}Here are your horses.", null), null).Condition(() => this.GetNumQuestMountsInInventory() >= this._numMountsToBeDelivered).NpcLine(new TextObject("{=g8qb3Ame}Thank you.", null), null, null).Consequence(delegate
				{
					Campaign.Current.ConversationManager.ConversationEndOneShot += base.CompleteQuestWithSuccess;
				}).CloseDialog().PlayerOption(new TextObject("{=G5tyQj6N}Not yet.", null), null).NpcLine(new TextObject("{=sjTpEzju}Very well. We'll keep waiting.", null), null, null).CloseDialog().EndPlayerOptions();
			}

			// Token: 0x0600507B RID: 20603 RVA: 0x0016EC74 File Offset: 0x0016CE74
			private void OnQuestAccepted()
			{
				base.StartQuest();
				this._numMountsInInventory = this.GetNumQuestMountsInInventory();
				this._questJournalEntry = base.AddDiscreteLog(this._onQuestStartedLogText, this._journalTaskName, MBMath.ClampInt(this._numMountsInInventory, 0, this._numMountsToBeDelivered), this._numMountsToBeDelivered, null, false);
			}

			// Token: 0x0600507C RID: 20604 RVA: 0x0016ECC5 File Offset: 0x0016CEC5
			private void OnQuestDeclined()
			{
				base.AddLog(this._onQuestFailedLogText, false);
				base.CompleteQuestWithFail(null);
			}

			// Token: 0x0600507D RID: 20605 RVA: 0x0016ECDC File Offset: 0x0016CEDC
			protected override void RegisterEvents()
			{
				CampaignEvents.PlayerInventoryExchangeEvent.AddNonSerializedListener(this, new Action<List<ValueTuple<ItemRosterElement, int>>, List<ValueTuple<ItemRosterElement, int>>, bool>(this.OnPlayerInventoryExchange));
				CampaignEvents.WarDeclared.AddNonSerializedListener(this, new Action<IFaction, IFaction, DeclareWarAction.DeclareWarDetail>(this.OnWarDeclared));
				CampaignEvents.OnClanChangedKingdomEvent.AddNonSerializedListener(this, new Action<Clan, Kingdom, Kingdom, ChangeKingdomAction.ChangeKingdomActionDetail, bool>(this.OnClanChangedKingdom));
				CampaignEvents.HeroPrisonerTaken.AddNonSerializedListener(this, new Action<PartyBase, Hero>(this.OnHeroPrisonerTaken));
				CampaignEvents.MapEventStarted.AddNonSerializedListener(this, new Action<MapEvent, PartyBase, PartyBase>(this.OnMapEventStarted));
				CampaignEvents.SettlementEntered.AddNonSerializedListener(this, new Action<MobileParty, Settlement, Hero>(this.OnSettlementEntered));
			}

			// Token: 0x0600507E RID: 20606 RVA: 0x0016ED74 File Offset: 0x0016CF74
			private void OnSettlementEntered(MobileParty mobileParty, Settlement settlement, Hero hero)
			{
				if (!Campaign.Current.ConversationManager.IsConversationFlowActive && hero == Hero.MainHero && mobileParty == MobileParty.MainParty && settlement.IsFortification && settlement.OwnerClan == base.QuestGiver.Clan)
				{
					MobileParty garrisonParty = Settlement.CurrentSettlement.Town.GarrisonParty;
					MBList<TroopRosterElement> mblist;
					if (garrisonParty == null)
					{
						mblist = null;
					}
					else
					{
						TroopRoster memberRoster = garrisonParty.MemberRoster;
						mblist = ((memberRoster != null) ? memberRoster.GetTroopRoster() : null);
					}
					MBList<TroopRosterElement> mblist2 = mblist;
					CharacterObject questGiversAgentCharacterObject;
					if (mblist2 == null || mblist2.Count == 0)
					{
						questGiversAgentCharacterObject = base.QuestGiver.Culture.Guard;
					}
					else
					{
						questGiversAgentCharacterObject = mblist2.MaxBy((TroopRosterElement troop) => troop.Character.Tier).Character;
					}
					this._questGiversAgentCharacterObject = questGiversAgentCharacterObject;
					CampaignMapConversation.OpenConversation(new ConversationCharacterData(CharacterObject.PlayerCharacter, PartyBase.MainParty, false, false, false, false, false, false), new ConversationCharacterData(this._questGiversAgentCharacterObject, null, false, false, false, false, false, false));
				}
			}

			// Token: 0x0600507F RID: 20607 RVA: 0x0016EE72 File Offset: 0x0016D072
			private void OnMapEventStarted(MapEvent mapEvent, PartyBase attackerParty, PartyBase defenderParty)
			{
				if (QuestHelper.CheckMinorMajorCoercion(this, mapEvent, attackerParty))
				{
					QuestHelper.ApplyGenericMinorMajorCoercionConsequences(this, mapEvent);
				}
			}

			// Token: 0x06005080 RID: 20608 RVA: 0x0016EE88 File Offset: 0x0016D088
			private void UpdateQuestJournalEntry()
			{
				int num = MBMath.ClampInt(this._numMountsInInventory, 0, this._numMountsToBeDelivered);
				if (num != this._questJournalEntry.CurrentProgress)
				{
					base.UpdateQuestTaskStage(this._questJournalEntry, num);
				}
			}

			// Token: 0x06005081 RID: 20609 RVA: 0x0016EEC4 File Offset: 0x0016D0C4
			private void CheckAndHandleQuestSuccessConditions()
			{
				int numQuestMountsInInventory = this.GetNumQuestMountsInInventory();
				if (numQuestMountsInInventory != this._numMountsInInventory)
				{
					if (this._numMountsInInventory < this._numMountsToBeDelivered && numQuestMountsInInventory >= this._numMountsToBeDelivered)
					{
						MBInformationManager.AddQuickInformation(this._onQuestMountRequirementSatisfiedQuickText, 0, null, "");
					}
					else if (this._numMountsInInventory >= this._numMountsToBeDelivered && numQuestMountsInInventory < this._numMountsToBeDelivered)
					{
						MBInformationManager.AddQuickInformation(this._onQuestMountRequirementNotSatisfiedQuickText, 0, null, "");
					}
					this._numMountsInInventory = numQuestMountsInInventory;
					this.UpdateQuestJournalEntry();
				}
			}

			// Token: 0x06005082 RID: 20610 RVA: 0x0016EF44 File Offset: 0x0016D144
			protected override void HourlyTick()
			{
				int versionNo = MobileParty.MainParty.ItemRoster.VersionNo;
				if (this._playerInventoryVersionNo != versionNo)
				{
					this.CheckAndHandleQuestSuccessConditions();
					this._playerInventoryVersionNo = versionNo;
				}
			}

			// Token: 0x06005083 RID: 20611 RVA: 0x0016EF78 File Offset: 0x0016D178
			private void OnPlayerInventoryExchange(List<ValueTuple<ItemRosterElement, int>> purchasedItems, List<ValueTuple<ItemRosterElement, int>> soldItems, bool isTrading)
			{
				bool flag = false;
				foreach (ValueTuple<ItemRosterElement, int> valueTuple in purchasedItems)
				{
					ItemRosterElement item = valueTuple.Item1;
					if (item.EquipmentElement.Item == this._mountObjectToBeDelivered)
					{
						flag = true;
						break;
					}
				}
				bool flag2 = false;
				foreach (ValueTuple<ItemRosterElement, int> valueTuple2 in soldItems)
				{
					ItemRosterElement item = valueTuple2.Item1;
					if (item.EquipmentElement.Item == this._mountObjectToBeDelivered)
					{
						flag2 = true;
						break;
					}
				}
				if (flag || flag2)
				{
					this.CheckAndHandleQuestSuccessConditions();
				}
				this._playerInventoryVersionNo = MobileParty.MainParty.ItemRoster.VersionNo;
			}

			// Token: 0x06005084 RID: 20612 RVA: 0x0016F064 File Offset: 0x0016D264
			private void OnHeroPrisonerTaken(PartyBase capturer, Hero prisoner)
			{
				if (prisoner == base.QuestGiver)
				{
					base.CompleteQuestWithCancel(this._onQuestCancelled3LogText);
				}
			}

			// Token: 0x06005085 RID: 20613 RVA: 0x0016F07B File Offset: 0x0016D27B
			private void OnClanChangedKingdom(Clan clan, Kingdom oldKingdom, Kingdom newKingdom, ChangeKingdomAction.ChangeKingdomActionDetail detail, bool showNotification = true)
			{
				if (base.QuestGiver.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction))
				{
					base.CompleteQuestWithCancel(this._onQuestCancelled2LogText);
				}
			}

			// Token: 0x06005086 RID: 20614 RVA: 0x0016F0A5 File Offset: 0x0016D2A5
			private void OnWarDeclared(IFaction faction1, IFaction faction2, DeclareWarAction.DeclareWarDetail detail)
			{
				QuestHelper.CheckWarDeclarationAndFailOrCancelTheQuest(this, faction1, faction2, detail, this._playerDeclaredWarQuestLogText, this._onQuestCancelled2LogText, false);
			}

			// Token: 0x06005087 RID: 20615 RVA: 0x0016F0C0 File Offset: 0x0016D2C0
			protected override void OnCompleteWithSuccess()
			{
				base.AddLog(this._onQuestSucceededLogText, false);
				int num = this._numMountsToBeDelivered;
				foreach (ItemRosterElement item in MobileParty.MainParty.ItemRoster)
				{
					if (item.EquipmentElement.Item == this._mountObjectToBeDelivered)
					{
						int amount = item.Amount;
						if (amount >= num)
						{
							this.GiveMounts(Hero.MainHero, base.QuestGiver, item, num);
							break;
						}
						num -= amount;
						this.GiveMounts(Hero.MainHero, base.QuestGiver, item, amount);
					}
				}
				GainRenownAction.Apply(Hero.MainHero, 1f, false);
				GiveGoldAction.ApplyForQuestBetweenCharacters(base.QuestGiver, Hero.MainHero, this.RewardGold, false);
				this.RelationshipChangeWithQuestGiver = 2;
			}

			// Token: 0x06005088 RID: 20616 RVA: 0x0016F1A4 File Offset: 0x0016D3A4
			private void GiveMounts(Hero giver, Hero receiver, ItemRosterElement item, int count)
			{
				if (giver.PartyBelongedTo != null)
				{
					giver.PartyBelongedTo.Party.ItemRoster.AddToCounts(item.EquipmentElement, -count);
					if (receiver.PartyBelongedTo != null)
					{
						receiver.PartyBelongedTo.Party.ItemRoster.AddToCounts(item.EquipmentElement, count);
					}
				}
			}

			// Token: 0x06005089 RID: 20617 RVA: 0x0016F200 File Offset: 0x0016D400
			protected override void OnFinalize()
			{
				base.RemoveTrackedObject(base.QuestGiver);
			}

			// Token: 0x0600508A RID: 20618 RVA: 0x0016F20E File Offset: 0x0016D40E
			public override void OnFailed()
			{
				this.RelationshipChangeWithQuestGiver = -3;
			}

			// Token: 0x0600508B RID: 20619 RVA: 0x0016F218 File Offset: 0x0016D418
			protected override void OnTimedOut()
			{
				base.AddLog(this._onQuestTimedOutLogText, false);
				this.RelationshipChangeWithQuestGiver = -5;
			}

			// Token: 0x0600508C RID: 20620 RVA: 0x0016F230 File Offset: 0x0016D430
			private int GetNumQuestMountsInInventory()
			{
				int num = 0;
				foreach (ItemRosterElement itemRosterElement in MobileParty.MainParty.ItemRoster)
				{
					if (itemRosterElement.EquipmentElement.Item == this._mountObjectToBeDelivered)
					{
						num += itemRosterElement.Amount;
					}
				}
				return num;
			}

			// Token: 0x04001A80 RID: 6784
			private const int RenownChangeOnSuccess = 1;

			// Token: 0x04001A81 RID: 6785
			private const int RelationChangeOnSuccess = 2;

			// Token: 0x04001A82 RID: 6786
			private const int RelationChangeOnFailure = -3;

			// Token: 0x04001A83 RID: 6787
			private const int RelationChangeOnTimeOut = -5;

			// Token: 0x04001A84 RID: 6788
			[SaveableField(1)]
			private readonly int _numMountsToBeDelivered;

			// Token: 0x04001A85 RID: 6789
			[SaveableField(2)]
			private readonly ItemObject _mountObjectToBeDelivered;

			// Token: 0x04001A86 RID: 6790
			[SaveableField(3)]
			private JournalLog _questJournalEntry;

			// Token: 0x04001A87 RID: 6791
			private int _numMountsInInventory;

			// Token: 0x04001A88 RID: 6792
			private int _playerInventoryVersionNo;

			// Token: 0x04001A89 RID: 6793
			private CharacterObject _questGiversAgentCharacterObject;
		}

		// Token: 0x0200064F RID: 1615
		public class LordNeedsHorsesIssueBehaviorTypeDefiner : SaveableTypeDefiner
		{
			// Token: 0x06005095 RID: 20629 RVA: 0x0016F333 File Offset: 0x0016D533
			public LordNeedsHorsesIssueBehaviorTypeDefiner() : base(510000)
			{
			}

			// Token: 0x06005096 RID: 20630 RVA: 0x0016F340 File Offset: 0x0016D540
			protected override void DefineClassTypes()
			{
				base.AddClassDefinition(typeof(LordNeedsHorsesIssueBehavior.LordNeedsHorsesIssue), 1, null);
				base.AddClassDefinition(typeof(LordNeedsHorsesIssueBehavior.LordNeedsHorsesIssueQuest), 2, null);
			}

			// Token: 0x06005097 RID: 20631 RVA: 0x0016F366 File Offset: 0x0016D566
			protected override void DefineEnumTypes()
			{
			}
		}
	}
}
